//
//  TravelTactic_MainCollectionReusableView.m
//  BTRIP
//
//  Created by Rain on 15/11/14.
//  Copyright © 2015年 johnbk. All rights reserved.
//

#import "TravelTactic_MainCollectionReusableView.h"

@interface TravelTactic_MainCollectionReusableView ()

@property (nonatomic, retain) NSArray *array;
@property (nonatomic, retain) UIView *lineView_One;
@property (nonatomic, retain) UIView *lineView_Two;

@end

@implementation TravelTactic_MainCollectionReusableView

- (void)dealloc {
    [_lineView_One release];
    [_lineView_Two release];
    [_titleLabel release];
    [_array release];
    
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame {
    
    self = [super initWithFrame:frame];
    if (self) {
        self.array = [NSArray array];
        self.array = @[@"亚洲", @"欧洲", @"美洲、大洋洲、非洲与南极洲", @"台港澳", @"大陆"];
        
        self.titleLabel = [[UILabel alloc] init];
        self.titleLabel.font = [UIFont systemFontOfSize:14];
        self.titleLabel.numberOfLines = 1;
        self.titleLabel.textAlignment = NSTextAlignmentCenter;
        [self addSubview:self.titleLabel];
        [self.titleLabel release];
        
        self.lineView_One = [[UIView alloc] init];
        self.lineView_One.backgroundColor = [UIColor lightGrayColor];
        self.lineView_One.alpha = .8;
        [self addSubview:self.lineView_One];
        [self.lineView_One release];
        
        self.lineView_Two = [[UIView alloc] init];
        self.lineView_Two.backgroundColor = [UIColor lightGrayColor];
        self.lineView_Two.alpha = .8;
        [self addSubview:self.lineView_Two];
        [self.lineView_Two release];
        
    }
    return self;
}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    if ([_titleLabel.text isEqualToString:@"美洲、大洋洲、非洲与南极洲"]) {
        CGFloat textWidth = 182 * SWIDTH;
        self.titleLabel.frame = CGRectMake((KWIDTH - textWidth) / 2, 3 * SWIDTH, textWidth, self.frame.size.height);
        self.lineView_One.frame = CGRectMake(5 * SWIDTH, self.frame.size.height / 2 - 1, KWIDTH / 2 - 10 * SWIDTH - textWidth / 2, 1);
        self.lineView_Two.frame = CGRectMake(self.titleLabel.frame.origin.x + self.titleLabel.frame.size.width + 5 * SWIDTH, self.frame.size.height / 2 - 1, KWIDTH / 2 - 10 * SWIDTH - textWidth / 2, 1);
    } else {
        CGFloat textWidth = 56 * SWIDTH;
        self.titleLabel.frame = CGRectMake((KWIDTH - textWidth) / 2, 3 * SWIDTH, textWidth, self.frame.size.height);
        self.lineView_One.frame = CGRectMake(5 * SWIDTH, self.frame.size.height / 2 - 1, KWIDTH / 2 - 10 * SWIDTH - textWidth / 2, 1);
        self.lineView_Two.frame = CGRectMake(self.titleLabel.frame.origin.x + self.titleLabel.frame.size.width + 5 * SWIDTH, self.frame.size.height / 2 - 1, KWIDTH / 2 - 10 * SWIDTH - textWidth / 2, 1);
    }
    
//    self.titleLabel.frame = CGRectMake((KWIDTH - 182.000000) / 2, 3 * SWIDTH, 182.000000, self.frame.size.height);
//    self.lineView_One.frame = CGRectMake(5 * SWIDTH, self.frame.size.height / 2 - 1, KWIDTH / 2 - 10 * SWIDTH - textWidth / 2, 1);
//    self.lineView_Two.frame = CGRectMake(self.titleLabel.frame.origin.x + self.titleLabel.frame.size.width + 5 * SWIDTH, self.frame.size.height / 2 - 1, KWIDTH / 2 - 10 * SWIDTH - textWidth / 2, 1);
    
}

+ (CGFloat)widthOfText:(NSString *)text font:(CGFloat)font {
    
    CGSize size = CGSizeMake(MAXFLOAT, 30 * SWIDTH);
    
    NSDictionary *dic = [NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:font] forKey:NSFontAttributeName];
    
    CGRect rect = [text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    
    return rect.size.width;
    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
